package com.gxa.shop.servlet.cart;

import com.alibaba.fastjson.JSON;
import com.gxa.shop.bean.pojo.Carousel;
import com.gxa.shop.bean.pojo.Cart;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.service.carousel.CarouselService;
import com.gxa.shop.service.carousel.impl.CarouselServiceImpl;
import com.gxa.shop.service.cart.CartService;
import com.gxa.shop.service.cart.Impl.CartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * com.gxa.shop.servlet.cart
 * User: 刁彦侨
 * Date: 2024/12/20 20:52
 * motto:   逆水行舟不进则退
 * Description:
 * Version: V1.0
 */
@WebServlet(name = "cart.UpdateByIdServlet", value = "/cart/updateById")
public class UpdateByIdServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader bufferedReader = request.getReader();
        String req_data = bufferedReader.readLine();
        Cart cart = JSON.parseObject(req_data, Cart.class);
        CartService cartService = new CartServiceImpl();
        boolean update = cartService.updateCart(cart);
        R r = update ? R.ok() : R.error("修改失败");
        PrintWriter writer = response.getWriter();
        String result = JSON.toJSONString(r);
        System.out.println("carousel.UpdateByIdServlet:"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}
